package com.mywork.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mywork.dao.ConsumptionViewMapper;
import com.mywork.dao.DrugMapper;
import com.mywork.dao.EquipmentConsumptionMapper;
import com.mywork.po.ConsumptionView;
import com.mywork.po.EquipmentConsumption;
import com.mywork.po.Page;

@Service
public class EquipmentConsumptionService {

	@Autowired
	ConsumptionViewMapper cvDao;
	
	@Autowired
	DrugMapper drugDao;
	
	
	@Autowired
	EquipmentConsumptionMapper ecDao;
	
	public int getCountOfList() {
		// TODO 自动生成的方法存根
		return cvDao.getCountOfAll();
	}
	public List<ConsumptionView> getAll(Page page) {
		// TODO 自动生成的方法存根
		return cvDao.getAll(page.getPageNo()*page.getPageSize(),page.getPageSize());
	}
	/**
	 * 添加物品消耗列表
	 * @param userId
	 * @param drugId
	 * @param count
	 */
	public void addConsumption(String userId, String[] drugId, String[] count) {
		// TODO 自动生成的方法存根
		
		for(int i=0;i<drugId.length;i++){
			EquipmentConsumption ec = new EquipmentConsumption();
			ec.setCount(Integer.valueOf(count[i]).intValue());
			ec.setDrugid(Long.valueOf(drugId[i]).longValue());
			ec.setUserid(userId);
			ec.setDate(new Date());
			ecDao.insert(ec);
			
			drugDao.updateForConsumptionCount(drugId[i],count[i]);
		}
	}

}
